package com.lehecai.core.api.credit;

import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.util.CoreDateUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * Created by zhangzq on 14-2-21.
 */
public class CreditExchangeDetails extends AbstractApiResultBean {

    public static final String QUERY_EXCHANGE_ID = "exchange_id";//兑换id
    public static final String QUERY_USER_ID = "uid";//用户uid
    public static final String QUERY_ID = "goods_id";//商品id

    private String exchange_id;			    //兑换id
    private String uid;                    //用户uid
    private Integer goods_id;	            //商品id
    private Integer num;                    //兑换量
    private Date timeline;                  //兑换时间

    public static CreditExchangeDetails convertFromJSONObject(JSONObject object) {
        if (object == null) {
            return null;
        }
        CreditExchangeDetails creditExchangeDetails = new CreditExchangeDetails();
        creditExchangeDetails.exchange_id = getString(object, "exchange_id");
        creditExchangeDetails.uid = getString(object, "uid");
        creditExchangeDetails.goods_id = getInt(object, "goods_id");
        creditExchangeDetails.num = getInt(object, "num");
        creditExchangeDetails.timeline = CoreDateUtils.parseDate(getString(object, "timeline"), CoreDateUtils.DATETIME);
        return creditExchangeDetails;
    }

    public static List<CreditExchangeDetails> convertFromJSONArray(JSONArray array) {
        if (array == null) {
            return null;
        }
        List<CreditExchangeDetails> list = new ArrayList<CreditExchangeDetails>();
        for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
            JSONObject object = (JSONObject) iterator.next();
            list.add(convertFromJSONObject(object));
        }
        return list;
    }

    public String getExchange_id() {
        return exchange_id;
    }

    public void setExchange_id(String exchange_id) {
        this.exchange_id = exchange_id;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public Integer getGoods_id() {
        return goods_id;
    }

    public void setGoods_id(Integer goods_id) {
        this.goods_id = goods_id;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    public Date getTimeline() {
        return timeline;
    }

    public void setTimeline(Date timeline) {
        this.timeline = timeline;
    }
}
